﻿Imports System.Data.OleDb

Public Class frmGiaSanPhamTheoKhachHang
    Private bEdit As Boolean

    '#Region "Thêm Sản Phẩm"
    '    Private Sub SanPham_Search(ByVal KeyWord As String)
    '        Try
    '            Dim dbConn As New OleDb.OleDbConnection
    '            Dim dataAccess As New DataAccess
    '            Dim dsSanPham As New DataSet
    '            Dim dtSanPham As New DataTable
    '            Dim query As String = "Select IDSanPham,MaLoai,TenLoai,MaSanPham,TenSanPham,TenDonViTinh,DonViTinh.TenDonVi,SanPham.GhiChu,SanPham.Xoa,SanPham.DonGia From SanPham " & _
    '                                    " Left Outer Join LoaiSanPham On SanPham.IdLoai=LoaiSanPham.IdLoai " & _
    '                                    " Left Outer Join DVTSanPham On SanPham.DVTSanPhamId=DVTSanPham.DVTSanPhamId" & _
    '                                    " Left Outer Join DonViTinh On DonViTinh.IdDonVi=DVTSanPham.IDDonViTinh" & _
    '                                    " Where SanPham.Xoa=0 And SanPham.MaSanPham Like N'%" & KeyWord & "%' Or SanPham.TenSanPham Like N'%" & KeyWord & "%'  Order By TenSanPham"
    '            Dim adapter As OleDb.OleDbDataAdapter
    '            dataAccess.ConnectDatabase_DBAccess(dbConn)
    '            adapter = New OleDb.OleDbDataAdapter(query, dbConn)
    '            adapter.Fill(dsSanPham)
    '            dbConn.Close()
    '            dgvSanPham_Search.AutoGenerateColumns = False
    '            dtSanPham = dsSanPham.Tables(0)
    '            dtSanPham.Columns.Add("STT")
    '            For i As Integer = 0 To dtSanPham.Rows.Count - 1
    '                dtSanPham.Rows(i)("STT") = i + 1
    '                'chú giải
    '            Next
    '            dgvSanPham_Search.DataSource = dtSanPham
    '            If dgvSanPham_Search.Rows.Count - 1 > 0 Then
    '                dgvSanPham_Search.Rows(0).Selected = True
    '            End If
    '        Catch ex As Exception
    '            ShowError()
    '        End Try
    '    End Sub

    '    Private Sub txtTenSanPham_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
    '        Try
    '            txtTenSanPham.BackColor = Color.White
    '        Catch ex As Exception

    '        End Try
    '    End Sub

    '    Private Sub txtTenSanPham_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '        Try
    '            If txtTenSanPham.Text <> "" Then
    '                'show search panel
    '                'If Not bEdit Then
    '                '    PanelSanPham_Search.Visible = True
    '                SanPham_Search(txtTenSanPham.Text)
    '                'Else
    '                PanelSanPham_Search.Visible = True
    '                'End If
    '            Else
    '                'hide search panel
    '                PanelSanPham_Search.Visible = False
    '            End If
    '        Catch ex As Exception
    '            ShowError()
    '        End Try
    '    End Sub
    '    Private Sub dgvSanPham_Search_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
    '        Try
    '            'Gan Du Lieu
    '            txtDonGiaI.Text = dgvSanPham_Search.Rows(dgvSanPham_Search.CurrentCell.RowIndex).Cells("DonGia").Value.ToString
    '            txtTenSanPham.Text = dgvSanPham_Search.Rows(dgvSanPham_Search.CurrentCell.RowIndex).Cells("MaSanPham").Value.ToString
    '            lblTenSanPham.Text = dgvSanPham_Search.Rows(dgvSanPham_Search.CurrentCell.RowIndex).Cells("TenSanPham").Value.ToString
    '            'hide search panel
    '            PanelSanPham_Search.Visible = False
    '        Catch ex As Exception
    '            ShowError()
    '        End Try
    '    End Sub
    '#End Region
    '#Region "Thêm Khách Hàng"
    '    Sub KhachHang_Quick_Search()
    '        Try
    '            Dim dbConn As New OleDb.OleDbConnection
    '            Dim dataAccess As New DataAccess
    '            Dim dsKhachHang As New DataSet
    '            Dim dtKhachHang As New DataTable
    '            Dim query As String = "Select KhachHangId,MaKhachHang,TenKhachHang,SoDienThoai,DiaChi From DanhMucKhachHang Where TenKhachHang Like N'%" & txtKhachHang.Text.Trim & "%'"
    '            Dim adapter As OleDb.OleDbDataAdapter
    '            dataAccess.ConnectDatabase_DBAccess(dbConn)
    '            adapter = New OleDb.OleDbDataAdapter(query, dbConn)
    '            adapter.Fill(dsKhachHang)
    '            dbConn.Close()
    '            dtKhachHang = dsKhachHang.Tables(0)
    '            Panel_KhachHang.Visible = True
    '            dgv_KhachHang_QuickSearch.AutoGenerateColumns = False
    '            dgv_KhachHang_QuickSearch.DataSource = dtKhachHang
    '        Catch ex As Exception
    '            MessageBox.Show(ex.ToString())
    '        End Try
    '    End Sub
    '    Private Sub dgv_KhachHang_QuickSearch_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
    '        Try

    '            Label1.Text = dgv_KhachHang_QuickSearch.Rows(dgv_KhachHang_QuickSearch.CurrentCell.RowIndex).Cells("KhachHangId_Search").Value.ToString()
    '            '---------Lấy Thống Tin Khách Hàng----------
    '            Dim dbConn As New OleDb.OleDbConnection
    '            Dim dataAccess As New DataAccess
    '            Dim dsTinhThanh As New DataSet
    '            Dim dtTinhThanh As New DataTable
    '            Dim query As String = "Select * From DanhMucKhachHang Where KhachHangId=" & Label1.Text
    '            Dim adapter As OleDb.OleDbDataAdapter
    '            dataAccess.ConnectDatabase_DBAccess(dbConn)
    '            adapter = New OleDb.OleDbDataAdapter(query, dbConn)
    '            adapter.Fill(dsTinhThanh)
    '            dbConn.Close()
    '            dtTinhThanh = dsTinhThanh.Tables(0)
    '            '
    '            txtKhachHang.Text = IIf(IsDBNull(dtTinhThanh.Rows(0)("TenKhachHang")), "", dtTinhThanh.Rows(0)("TenKhachHang"))
    '            '
    '            Panel_KhachHang.Visible = False
    '            cmdAddNew.Focus()
    '        Catch ex As Exception

    '        End Try
    '    End Sub
    '    Private Sub txtKhachHang_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
    '        Try
    '            If txtKhachHang.Text <> "" Then
    '                KhachHang_Quick_Search()
    '            Else
    '                Panel_KhachHang.Visible = False
    '            End If
    '        Catch ex As Exception
    '            MessageBox.Show(ex.ToString())
    '        End Try
    '    End Sub
    '    Private Sub cmdAddNew_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdAddNew.Enter
    '        Try
    '            Panel_KhachHang.Visible = False
    '            'kiem tra nếu tên khách hàng chua có trong list thi thong bao
    '            If IsNotExist() Then
    '                MessageBox.Show("Tên khách hàng bạn nhập chưa có trong danh mục.Vui lòng kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '                txtKhachHang.Focus()
    '            End If
    '        Catch ex As Exception

    '        End Try
    '    End Sub
    '    Function IsNotExist() As Boolean
    '        Try
    '            Dim dbConn As New OleDb.OleDbConnection
    '            Dim dataAccess As New DataAccess
    '            Dim dsKhachHang As New DataSet
    '            Dim dtKhachHang As New DataTable
    '            Dim query As String = "Select Count(*) From DanhMucKhachHang Where LOWER(TenKhachHang)=N'" & txtKhachHang.Text.ToLower.Trim & "'"
    '            Dim dbCommand As OleDb.OleDbCommand
    '            dataAccess.ConnectDatabase_DBAccess(dbConn)
    '            dbCommand = New OleDb.OleDbCommand(query, dbConn)
    '            Dim iResult As Integer
    '            iResult = dbCommand.ExecuteScalar()
    '            If iResult = 0 Then
    '                Return True
    '            Else
    '                Return False
    '            End If
    '            dbConn.Close()
    '        Catch ex As Exception
    '            MessageBox.Show(ex.ToString())
    '        End Try
    '    End Function
    '#End Region

    '    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '        Try
    '            Panel_KhachHang.Visible = False
    '        Catch ex As Exception

    '        End Try
    '    End Sub

    '    Private Sub cmdDong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '        Try
    '            PanelSanPham_Search.Visible = False
    '        Catch ex As Exception

    '        End Try
    '    End Sub
#Region "Thêm Sản phẩm - Khách hàng"
    Protected Function Create_BangGiaSanPhamTheoKhachHang() As DataTable
        Dim dtTable As DataTable = New DataTable()
        Try

            Dim STT As DataColumn = New DataColumn("STT")
            STT.DataType = System.Type.GetType("System.String")
            STT.DefaultValue = ""
            dtTable.Columns.Add(STT)

            Dim IDSanPham As DataColumn = New DataColumn("IDSanPham")
            IDSanPham.DataType = System.Type.GetType("System.Int32")
            dtTable.Columns.Add(IDSanPham)

            Dim MaSanPham As DataColumn = New DataColumn("MaSanPham")
            MaSanPham.DataType = System.Type.GetType("System.String")
            MaSanPham.DefaultValue = ""
            dtTable.Columns.Add(MaSanPham)

            Dim TenSanPham As DataColumn = New DataColumn("TenSanPham")
            TenSanPham.DataType = System.Type.GetType("System.String")
            TenSanPham.DefaultValue = ""
            dtTable.Columns.Add(TenSanPham)

            Dim DonGia As DataColumn = New DataColumn("DonGia")
            DonGia.DataType = System.Type.GetType("System.String")
            dtTable.Columns.Add(DonGia)

            Dim DonGiaII As DataColumn = New DataColumn("DonGiaII")
            DonGiaII.DataType = System.Type.GetType("System.String")
            dtTable.Columns.Add(DonGiaII)

            Dim IDKhachHang As DataColumn = New DataColumn("IDKhachHang")
            IDKhachHang.DataType = System.Type.GetType("System.String")
            dtTable.Columns.Add(IDKhachHang)

            Dim TenKhachHang As DataColumn = New DataColumn("TenKhachHang")
            TenKhachHang.DataType = System.Type.GetType("System.String")
            dtTable.Columns.Add(TenKhachHang)

            Return dtTable
        Catch ex As Exception
            Throw
        End Try
    End Function
#End Region
    Private Function KiemTraTonTaiSanPham(ByVal TenSanPham As String) As Integer
        Try
            Dim dataAccess As New DataAccess
            Dim dbConn As New OleDb.OleDbConnection
            dataAccess.ConnectDatabase_DBAccess(dbConn)
            Dim dbCommand As OleDbCommand
            Dim query As String = "Select IDSanPham From SanPham Where MaSanPham=N'" & TenSanPham & "'"
            dbCommand = New OleDbCommand(query, dbConn)
            If IsDBNull(dbCommand.ExecuteScalar) Then
                Return 0
            Else
                Return dbCommand.ExecuteScalar()
            End If
            dbConn.Close()
        Catch ex As Exception
            ShowError()
        End Try
    End Function
    'Private Sub cmdAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddNew.Click
    '    Try
    '        ShowModalForm(frmThemGiaSanPhamTheoKhachHang, False, False)
    '    Catch ex As Exception

    '    End Try
    'Try
    '    Dim IDSanPham As Integer
    '    Dim MaSanPham As String = txtTenSanPham.Text.Trim
    '    Dim TenSanPham As String = lblTenSanPham.Text.Trim
    '    Dim DonGia As String = txtDonGiaI.Text
    '    Dim DonGiaI As String = txtDonGiaII.Text
    '    Dim IDKhachHang As String = Label1.Text
    '    Dim TenKhachHang As String = txtKhachHang.Text
    'IDSanPham = KiemTraTonTaiSanPham(txtTenSanPham.Text)
    '    If txtDonGiaII.Text = "" Then
    '        txtDonGiaII.BackColor = Color.FromArgb(192, 255, 255)
    '        txtDonGiaII.Focus()
    '        Exit Sub
    '    End If
    '    If IDSanPham = 0 Then
    '        MessageBox.Show("Tên sản phẩm không có trong danh mục.Vui lòng kiểm tra lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '        EmptyData(txtTenSanPham)
    '        Exit Sub
    '    Else
    '        If bEdit Then
    '            'Dim rowUpdate() As DataRow
    '            'rowUpdate = BangGiaSanPhamTheoKhachHang.Select("IDSanPham=" & IDSanPham & " And IDKhachHang=" & IDKhachHang)
    '            'If rowUpdate.Length > 0 Then
    '            '    MessageBox.Show("Giá của sản phẩm này với khách hàng đã có trong danh mục.Vui lòng kiểm tra lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '            '    Exit Sub
    '            'End If
    '        Else
    '            Dim rowUpdate() As DataRow
    '            rowUpdate = BangGiaSanPhamTheoKhachHang.Select("IDSanPham=" & IDSanPham & " And IDKhachHang=" & IDKhachHang)
    '            If rowUpdate.Length > 0 Then
    '                MessageBox.Show("Giá của sản phẩm này với khách hàng đã có trong danh mục.Vui lòng kiểm tra lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '                Exit Sub
    '            Else
    '            Dim newRow As DataRow
    '            newRow = BangGiaSanPhamTheoKhachHang.NewRow
    '            newRow.Item("IDSanPham") = IDSanPham
    '            newRow.Item("MaSanPham") = MaSanPham
    '            newRow.Item("TenSanPham") = TenSanPham
    '            newRow.Item("DonGia") = DonGia
    '            newRow.Item("DonGiaII") = DonGiaI
    '            newRow.Item("IDKhachHang") = IDKhachHang
    '            newRow.Item("TenKhachHang") = TenKhachHang
    '            BangGiaSanPhamTheoKhachHang.Rows.Add(newRow)
    '        End If
    '        End If
    '    End If
    '    'bind data
    '    Grid1.Rows.Clear()
    '    txtTenSanPham.Text = ""
    '    lblTenSanPham.Text = ""
    '    txtDonGiaI.Text = "0.00"
    '    txtDonGiaII.Text = "0.00"
    '    Label1.Text = "0"
    '    txtKhachHang.Text = ""
    '    bEdit = False
    '    CreateHeader()
    '    CreateDetail(BangGiaSanPhamTheoKhachHang)
    '    'BindDataNewOrder(ChiTietPhieuNhapKho)

    '    'End If
    'Catch ex As Exception
    '    ShowError()
    'End Try
    'End Sub
    Private BangGiaSanPhamTheoKhachHang As New DataTable

#Region " Form Load"
    Private Sub frmGiaSanPhamTheoKhachHang_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            SanPhamNhieuGia_Load()
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region " Load Data"
    Private Sub CreateHeader()
        Try
            Grid1.ColumnsCount = 6
            Grid1.Rows.Clear()
            'tạo header 
            Grid1.FixedRows = 1
            Grid1.Rows.Insert(0)
            Dim rowCOLSPAN As New SourceGrid.Cells.Views.Cell
            Dim fontBold As New Font(Grid1.Font, FontStyle.Bold)
            rowCOLSPAN.Font = fontBold
            Grid1(0, 0) = New SourceGrid.Cells.ColumnHeader("STT")
            Grid1(0, 0).Column.Width = 40
            Grid1(0, 0).View.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter
            Grid1(0, 0).View.Font = Grid1.Font

            Grid1(0, 1) = New SourceGrid.Cells.ColumnHeader("Tên khách hàng")
            Grid1(0, 1).Column.Width = 250
            Grid1(0, 1).View.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft
            Grid1(0, 1).View.Font = Grid1.Font

            Grid1(0, 2) = New SourceGrid.Cells.ColumnHeader("Địa chỉ")
            Grid1(0, 2).Column.Width = 350
            Grid1(0, 2).View.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft
            Grid1(0, 2).View.Font = Grid1.Font

            Grid1(0, 3) = New SourceGrid.Cells.ColumnHeader("Đơn giá I")
            Grid1(0, 3).Column.Width = 120
            Grid1(0, 3).View.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter
            Grid1(0, 3).View.Font = Grid1.Font


            Grid1(0, 4) = New SourceGrid.Cells.ColumnHeader("Đơn giá II")
            Grid1(0, 4).Column.Width = 120
            Grid1(0, 4).View.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter
            Grid1(0, 4).View.Font = Grid1.Font

            Grid1(0, 5) = New SourceGrid.Cells.ColumnHeader("GiaId")
            Grid1(0, 5).Column.Width = 0
            Grid1(0, 5).View.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter
            Grid1(0, 5).View.Font = Grid1.Font
        Catch ex As Exception

        End Try
    End Sub
    Private Sub CreateDetail(ByVal dtBangGiaSanPhamTheoKhachHang As DataTable)
        Try
            REM SELECT DISTINCT IDSANPHAM
            Dim distinctIDSanPham As DataTable
            Dim datasetHelper As New DataSetHelper
            distinctIDSanPham = datasetHelper.SelectDistinct("distinctIDSanPham", dtBangGiaSanPhamTheoKhachHang, "IDSanPham")
            Dim nextRowIndex As Integer = 1
            Dim cellNumberStyle As New SourceGrid.Cells.Views.Cell
            cellNumberStyle.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleRight
            Dim cellTextStyle As New SourceGrid.Cells.Views.Cell
            cellTextStyle.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft
            Dim cellGrouping As New SourceGrid.Cells.Views.Cell
            cellGrouping.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft
            cellGrouping.BackColor = Color.FromArgb(192, 255, 192)
            Dim cellOrder As New SourceGrid.Cells.Views.Cell
            cellOrder.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter
            For i As Integer = 0 To distinctIDSanPham.Rows.Count - 1
                'Group Title 
                Dim rowDetail() As DataRow
                rowDetail = dtBangGiaSanPhamTheoKhachHang.Select("IDSanPham=" & distinctIDSanPham.Rows(i)("IDSanPham"))
                Grid1.Rows.Insert(nextRowIndex)
                Grid1(nextRowIndex, 0) = New SourceGrid.Cells.Cell("Sản phẩm: " & rowDetail(0)("TenSanPham") & " - Mã sản phẩm: " & rowDetail(0)("MaSanPham"))
                Grid1(nextRowIndex, 0).ColumnSpan = 6
                Grid1(nextRowIndex, 0).View = cellGrouping
                Dim ci As New Globalization.CultureInfo("en-us")
                Dim DonGiaI As Double
                Dim DonGiaII As Double
                For j As Integer = 0 To rowDetail.Length - 1
                    nextRowIndex = nextRowIndex + 1
                    Grid1.Rows.Insert(nextRowIndex)
                    Grid1(nextRowIndex, 0) = New SourceGrid.Cells.Cell(j + 1)
                    Grid1(nextRowIndex, 0).View = cellOrder
                    Grid1(nextRowIndex, 1) = New SourceGrid.Cells.Cell(rowDetail(j)("TenKhachHang"))
                    Grid1(nextRowIndex, 1).View = cellTextStyle
                    Grid1(nextRowIndex, 2) = New SourceGrid.Cells.Cell(rowDetail(j)("DiaChi"))
                    Grid1(nextRowIndex, 2).View = cellTextStyle
                    DonGiaI = Double.Parse(rowDetail(j)("DonGia"), Globalization.NumberStyles.Currency)
                    Grid1(nextRowIndex, 3) = New SourceGrid.Cells.Cell(DonGiaI.ToString("N02", ci))
                    Grid1(nextRowIndex, 3).View = cellNumberStyle
                    DonGiaII = Double.Parse(rowDetail(j)("DonGiaII"), Globalization.NumberStyles.Currency)
                    Grid1(nextRowIndex, 4) = New SourceGrid.Cells.Cell(DonGiaII.ToString("N02", ci))
                    Grid1(nextRowIndex, 4).View = cellNumberStyle
                    Grid1(nextRowIndex, 5) = New SourceGrid.Cells.Cell(rowDetail(j)("GiaId"))
                    Grid1(nextRowIndex, 5).View = cellNumberStyle
                Next
                nextRowIndex = nextRowIndex + 1
            Next
        Catch ex As Exception

        End Try
    End Sub
    Private Sub SanPhamNhieuGia_Load()
        Try
            Dim dbConn As New OleDb.OleDbConnection
            Dim dataAccess As New DataAccess
            Dim dtSanPhamNhieuGia As New DataTable
            Dim query As String = "Select SPM.GiaId,SP.IDSanPham,SP.MaSanPham,SP.TenSanPham,SP.DonGia,SPM.DonGiaII,KH.KhachHangID,KH.TenKhachHang,KH.DiaChi From SanPhamNhieuGia As SPM" & _
                                    " Left Outer Join SanPham As SP On SP.IDSanPham=SPM.IDSanPham" & _
                                    " Left Outer Join DanhMucKhachHang As KH On KH.KhachHangID = SPM.IDKhachHang" & _
                                    " Where SPM.Xoa=0 And KH.TenKhachHang Like '%" & txtKhachHang.Text.Trim & "%' And ( SP.TenSanPham Like '%" & txtSanPham.Text.Trim & "%' Or SP.MaSanPham Like '%" & txtSanPham.Text.Trim & "%')"
            Dim adapter As OleDb.OleDbDataAdapter
            dataAccess.ConnectDatabase_DBAccess(dbConn)
            adapter = New OleDb.OleDbDataAdapter(query, dbConn)
            adapter.Fill(dtSanPhamNhieuGia)
            dbConn.Close()
            CreateHeader()
            CreateDetail(dtSanPhamNhieuGia)
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region " Thêm, Chỉnh sửa, Xóa"
    Private ColumnIndex As Integer = -1
    Private RowIndex As Integer = -1
    Private Sub Grid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Grid1.Click
        Try
            Dim cellSelected As SourceGrid.Selection.FreeSelection
            cellSelected = Grid1.Selection()
            ColumnIndex = cellSelected.ActivePosition.Column
            RowIndex = cellSelected.ActivePosition.Row
        Catch ex As Exception

        End Try
    End Sub
    Private Sub cmdEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEdit.Click
        Try
            Dim GiaId As Integer
            If ColumnIndex <> -1 And RowIndex <> -1 Then
                GiaId = Grid1(RowIndex, 5).Value
                frmThemGiaSanPhamTheoKhachHang.GiaId = GiaId
                ShowModalForm(frmThemGiaSanPhamTheoKhachHang, False, False)
                SanPhamNhieuGia_Load()
                frmThemGiaSanPhamTheoKhachHang.GiaId = -1
            End If
        Catch ex As Exception

        End Try
    End Sub
    Private Sub cmdAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddNew.Click
        Try
            ShowModalForm(frmThemGiaSanPhamTheoKhachHang, False, False)
            SanPhamNhieuGia_Load()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
        Dim GiaId As Integer
        If ColumnIndex <> -1 And RowIndex <> -1 Then
            GiaId = Grid1(RowIndex, 5).Value
            Dim dlgRes As DialogResult
            dlgRes = MessageBox.Show( _
                  "Bạn muốn xóa mục này", _
                  "Thông báo", _
            MessageBoxButtons.OKCancel, _
                  MessageBoxIcon.Warning)
            If dlgRes = DialogResult.OK Then
                Dim dataAccess As New DataAccess
                Dim dbConn As New OleDb.OleDbConnection
                Dim dbCommand As OleDbCommand
                dataAccess.ConnectDatabase_DBAccess(dbConn)
                Dim query As String = "Update SanPhamNhieuGia Set Xoa=1,NgayXoa='" & NgayTao() & "',NguoiXoa='" & NguoiTao() & "' Where GiaId=" & GiaId
                dbCommand = New OleDbCommand(query, dbConn)
                dbCommand.ExecuteNonQuery()
                dbConn.Close()
                SanPhamNhieuGia_Load()
            End If
            SanPhamNhieuGia_Load()
        End If
    End Sub
#End Region

    Private Sub cmdTimKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTimKiem.Click
        SanPhamNhieuGia_Load()
    End Sub

    Private Sub txtSanPham_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSanPham.TextChanged
        SanPhamNhieuGia_Load()
    End Sub

    Private Sub txtKhachHang_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtKhachHang.TextChanged
        SanPhamNhieuGia_Load()
    End Sub
End Class